const path = require('path')

function resolve (dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  baseUrl: process.env.VUE_APP_BASE_URL,
  devServer: {
    proxy: 'https://api.kaishui.cn/fingo/'
  },
  css: {
    modules: false,
    loaderOptions: {
      sass: {
        data: `@import "node_modules/sass-bem-constructor/dist/bem-constructor.scss";@import "@/styles/variables.scss";`
      }
    }
  },
  chainWebpack: config => {
    config.plugin('copy').tap(args => {
      args[0][0].ignore = ['.DS_Store']
      return args
    })
    addSvgLoader(config, config.module.rule('svg-sprite'))
  }
}

function addSvgLoader (config, rule) {
  var svgRule = config.module.rule('svg')
  svgRule.uses.clear()

  svgRule
    .exclude.add(resolve('src/icons')).end()
    .use('vue-svg-loader')
    .loader('vue-svg-loader')

  rule.test(/\.svg$/)
    .include.add(resolve('./src/icons')).end()
    .use('svg-sprite')
    .loader('svg-sprite-loader')
    .options({
      symbolId: 'icon-[name]'
    })
}
